<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>sessionStorage</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <h2>sessionStorage</h2>
    <button onclick="saveData()">点我保存数据</button>
    <button onclick="readData()">点我读取数据</button>
    <button onclick="deleteData()">点我删除数据</button>
    <button onclick="deleteAllData()">点我清空数据</button>
</body>
    <script type="text/javascript">
        let p = {name:'张三',age:18}

        function saveData(){
            window.sessionStorage.setItem('msg','hello!')
            window.sessionStorage.setItem('person',JSON.stringify(p))
        }
        function readData(){
            
            console.log(window.sessionStorage.getItem('msg'));
            console.log(JSON.parse( window.sessionStorage.getItem('person')));
        }
        function deleteData(){
            window.sessionStorage.removeItem('msg')
        }
        function deleteAllData(){
            window.sessionStorage.clear()
        }
    </script>
</html>